package com.wk.wkcomp.model

import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wk.lib_base.net.RequestStatus
import com.wk.lib_base.net.ResultData
import com.wk.lib_base.net.RetrofitUtil
import com.wk.lib_base.net.requestLiveData
import com.wk.wkcomp.Api

class TestViewModel : ViewModel() {
    val content = MediatorLiveData<ResultData<String>>()
    fun loadData() {
        val data = viewModelScope.requestLiveData<String, String> {
            api { RetrofitUtil.ins().create(Api::class.java).getWanAndroid() }
        }
        content.addSource(data) {
            if (it.requestStatus == RequestStatus.COMPLETE) {
                content.removeSource(data)
            }
            content.value = it
        }

    }
}